require(['loading'], function(loading) {
	var params = getUrlParams();
	var orderId = ''; 
	var orderStatus='';//订单状态
	orderId = params.order?params.order:'';
	orderStatus=params.orderStatus?params.orderStatus:'';
	console.log(orderStatus)
	var main_len;
	var amount;
	var images;
	var delimages;
	var vals;
	if (orderStatus==10) {
    $("#one").show();
    $("#wy_sc").hide();
    $("#moyc").hide();
    $(".contract").show();
    $("#da").show();
    $("#cjs").show();
    } 
    else if (orderStatus==20) {
    $("#two").show();
    $("#wy_sc").hide();
    $("#fixmoney").hide();
    $("#moyc").show();
    $("#da").show();
    $("#cjs").show();
    } 
    else if (orderStatus==30) {
    $("#three").show();
    $("#wy_sc").show();
    $("#fixmoney").hide();
    $("#moyc").show();
    $("#jyl").show();
    $("#xgs").show();
    $("#fhs").show();
    $("#da").show();
    $("#cjs").show();
    } else if 
    (orderStatus==40|| orderStatus == 60 || orderStatus == 65 || orderStatus == 70) {
    $("#four").show();
    $("#wy_sc").show();
    $("#fixmoney").hide();
    $("#moyc").show();
    $("#jyl").show();
    $("#xgs").show();
    $("#fhs").show();
    $("#da").show();
    $("#cjs").show();
    } else if 
    (orderStatus==50) {
    $("#five").show();
    $("#wy_sc").hide();
    $("#fixmoney").hide();
    $("#moyc").show();
    $("#da").show();
    $("#cjs").show();
                      } 
	var orderDetail = new Vue({
		el:'#container',
		data:{
			showLoading:false,
			hasPayPassword:false,
			contractTotal:0,
			freightProof: [],
		    mainImage: [],
		    mainImageStr: [],
			orderDetailUrl: wxUrl + '/v3.3/pforder/getOrder',
			changeMoney: wxUrl + '/v3.3/pforder/updateAmount',
			scwlPic:wxUrl+'/v3.3/pforder/trackImage',
			item: {
				params:{
					token: token,
					userToken: userToken,
					orderId:orderId
				}
			},
			item1: {
				params:{
					token: token,
					userToken: userToken,
					orderId:orderId,
					amount:amount
				}
			},
			addpic:{
				params:{
					token: token,
					userToken: userToken,
					orderId:orderId,
					type:"",
					images:images
				}
				
			},
			delpic:{
				params:{
					token: token,
					userToken: userToken,
					orderId:orderId,
					type:0,
					images:images
				}
				
			},
			data:{}
		},
		ready: function() {
	        this.loadOrderDetail();
	    },
		methods:{
			loadOrderDetail:function(){
				//获取订单详情列表
				this.$http.get(this.orderDetailUrl, this.item)
					.then(function(response) {
						var result = JSON.parse(response.body);
						console.log(result)
						vals=
						this.$set('data', result.data);
						var zj=result.data.order.order.goodsPrice*result.data.order.order.goodsAmount;
						var zprice=zj.toFixed(2);
						$("#totalAmount").text(zprice+"元");
						this.contractTotal=this.data.order.order.payAmount;
						/*this.contractTotal=this.contractTotal.toFixed(2);*/
                       /* var sjiprice=result.data.order.order.payAmount.toFixed(2);*/
                        var tbdz=result.data.order.order.freightProof;
                        console.log(tbdz)
                        if(tbdz==''||tbdz== null||tbdz==undefined){

                        }else{
                       var lesd=tbdz.split(",");
                       console.log(lesd)
                        this.mainImage= this.mainImage.concat(lesd);
                         }
                        /*$("#moyc").text(sjiprice + '元');*/
					},function(response) {
						//errorCallback
					});
			},
			fixmoney:function(){
				//上传修改金额
				this.$http.get(this.changeMoney, this.item1)
					.then(function(response) {
						var result = JSON.parse(response.body);
						console.log(result)
						if (result.code == 0) {
							var yespic = result.data.result;
                        if (yespic) {
                        	promptBox('修改成功！');
                        }
						}
						
					},function(response) {
						//errorCallback
					});
			},
			addPic:function(){
				this.$http.get(this.scwlPic, this.addpic)
					.then(function(response) {
						var result = JSON.parse(response.body);
						
						console.log(result)
						if (result.code == 0) {
							var yespic = result.data.result;
                        if (yespic) {
                        	promptBox('上传成功！');
                        }
						}
						
					},function(response) {
						//errorCallback
					});
				
			},
			delPic:function(){
				this.$http.get(this.scwlPic, this.delpic)
					.then(function(response) {
						var result = JSON.parse(response.body);
						console.log(result)
						if (result.code == 0) {
							var yespic = result.data.result;
                        if (yespic) {
                        	promptBox('删除成功！');
                        }
						}
						
					},function(response) {
						//errorCallback
					});
				
			}
		}
	});
	 $('#sumitagin').on('click', function(e) {
        var pricess = $("#contractTotal").val();
       var Loutput = /^(?!0+(?:\.0+)?$)(?:[1-9]\d*|0)(?:\.\d{1,2})?$/;
        if (Loutput.test(pricess)) {
            $(".overlay").show();
            $(".tanceng").show();
            $("body").addClass("fixeds");

        }else{
            promptBox('请输入合理价格！');
        }
    });
    $('.contract input').on('keyup', function() {
        $('.yanw').show();
    });
    $('.clear').click(function() {
    	$(this).hide();
    	$('#contractTotal').val('');
    });
    $(".delqx").on("click", function() {
        $(".overlay").hide();
        $(".tanceng").hide();
        $("body").removeClass("fixeds");
    })
    $(".enter").on("click", function() {
            $("body").removeClass("fixeds");
            $(".overlay").hide();
            $(".tanceng").hide();
            $(".contract").hide();
            $("#fixmoney").text($("#contractTotal").val());
            $("#fixmoney").addClass("lhg");
            orderDetail.item1.params.amount = $("#fixmoney").text();
            orderDetail.fixmoney();
            $("#two").show();
            $("#one").hide();
    })
    //上传主图 6张
	$('#uploadMainImgBtn').diyUpload({
		url: wxUrl + '/v3.3/personalInfo/upload',
		success: function(data) {
			console.info(data);
			if(data.data.success) {
				orderDetail.mainImage.push(data.data.fullurl);
				orderDetail.mainImageStr.push(data.data.url);
				var qcl=orderDetail.mainImage.join(",")
				orderDetail.addpic.params.images=qcl;
				orderDetail.addPic();
				main_len = ($('#sdd_uploads li').length)+1;
				if(main_len == 3) {
					$('#uploadMainImgBtn').hide();
				}
			} else {
				promptBox('上传失败！');
			}
		},
		error: function(err) {
			promptBox(err);
		}
	});
	//删除主图的图片
		$('#sdd_uploads').on('click', '.clearpic', function() {
            var imageUrls = $(this).parent().find('img').attr('src');
            orderDetail.delpic.params.images=imageUrls;
		    orderDetail.delPic();
			var  index  =  $('#sdd_uploads li').index($(this).closest('#sdd_uploads li'));
			orderDetail.mainImage.splice(index, 1);
			orderDetail.mainImageStr.splice(index, 1);
			main_len--;
			if(main_len < 3) {
				$('#uploadMainImgBtn').show();
			}
		});
    
	
});


